﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Golf.WebUI.Customers
{
    public partial class Account : System.Web.UI.Page
    {
        /// <summary>
        /// 定义常量，判断状态 判断客户是否登录  0未登录 1表示已登录
        /// </summary>
        public int loginState = 0;
        /// <summary>
        /// 邮箱
        /// </summary>
        public string Customer_Email;
        /// <summary>
        /// 登陆用户的id
        /// </summary>
        public int UserId = 0;
        /// <summary>
        /// 主机名称
        /// </summary>
        public string Host = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Host = ThumNail.GetHttpHost();
            Object obj = CookiesHelper.GetCookie("_Customer_id");
            Object bojEmail = CookiesHelper.GetCookie("_Customer_Email");
            if (obj == null || obj.ToString() == "")
            {
                loginState = 0;
            }
            else
            {
                UserId = int.Parse(obj.ToString());
                Golf.BLL.Golf_User u_bll = new Golf.BLL.Golf_User();
                Golf.Model.Golf_User model = u_bll.GetModel(UserId);
                if (model == null)
                    return;
                if (model.State == 0)
                {
                    loginState = 0;
                }
                else
                {
                    loginState = 1;
                }

            }
            if (bojEmail != null && bojEmail.ToString() != "")
            {  //存值
                Customer_Email = Server.UrlDecode(bojEmail.ToString());
            }
            if (!IsPostBack)
            {
                if (Request.Form["action"] != null)
                {
                    switch (Request.Form["action"])
                    {
                        case "loginout":
                            CookiesHelper.ClearCookie("_Customer_id");
                            CookiesHelper.ClearCookie("_Customer_Email");
                            Response.Write("0|");
                            break;
                    }
                }
            }
            DtateBind(UserId);
            DttateBindAddress(UserId);
            Order_History(UserId);
        }
        public Golf.Model.Golf_User user = new Model.Golf_User();
        public Golf.BLL.Golf_User userdate = new BLL.Golf_User();
        public Golf.BLL.Golf_UserData userdates = new BLL.Golf_UserData();
        #region

        public string _Name = "";
        public string _Email = "";
        #endregion
        /// <summary>
        /// 单个用户信息
        /// </summary>
        /// <param name="id">用户ID</param>
        public void DtateBind(int id)
        {
            Golf.Model.Golf_User model = userdate.GetModel(id);
            if (model == null) return;
            _Name = model.FristName + " " + model.LastName;
            _Email = model.Email;
        }
        /// <summary>
        /// 单个用户的详细地址
        /// </summary>
        /// <param name="id">用户ID</param>
        public void DttateBindAddress(int userid)
        {
            Golf.BLL.Golf_Address bll = new Golf.BLL.Golf_Address();
            List<Golf.Model.Golf_Address> list = bll.GetModelList("userid=" + userid);
            Repeater2.DataSource = list;
            Repeater2.DataBind();
        }
        /// <summary>
        /// 单个用户的详细地址
        /// </summary>
        /// <param name="id">用户ID</param>
        public void Order_History(int userid)
        {
            Golf.BLL.Golf_Order bll = new Golf.BLL.Golf_Order();
            List<Golf.Model.Golf_Order> list = bll.GetModelList("userid=" + userid);
            rep_Order_History.DataSource = list;
            rep_Order_History.DataBind();
        }
    }
}
